package com.vae.search.controller;

import com.vae.mall.common.response.RespResult;
import com.vae.search.model.SkuEs;
import com.vae.search.model.SpuEs;
import com.vae.search.service.SpuSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 *es的spu搜索控制层
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/search/spues")
public class SpuSearchController {
    @Autowired
    private SpuSearchService spuSearchService;

    /****
     * 添加单个spu到es
     */
    @PostMapping(value = "/add")
    public RespResult add(@RequestBody SpuEs spuEs){
        spuSearchService.add(spuEs);
        return RespResult.ok();
    }

    /***
     * 根据ID删除spu
     * @param id
     * @return
     */
    @DeleteMapping(value = "/del/{id}")
    public RespResult del(@PathVariable("id")String id){
        spuSearchService.del(id);
        return RespResult.ok();
    }

    /**
     * 根据条件搜索spu
     * @param searchMap
     */
    @GetMapping
    public RespResult<Map<String,Object>> search(@RequestParam(required = false) Map<String, Object> searchMap) {
        Map<String,Object> result = spuSearchService.search(searchMap);
        return RespResult.ok(result);
    }
}
